<!--
 * @Author: lsy
 * @Date: 2023-02-14 19:55:19
 * @LastEditors: lsy
 * @LastEditTime: 2023-02-14 21:37:25
 * @Description: 毕业作品浏览
-->
<template>
  <sc-dialog
    v-model="visible"
  >
    <template #header>
      毕业作品浏览
    </template>
    <div class="file-list">
      <div class="file-item" v-for="(file, idx) in fileList" :key="idx">
        <div v-if="isImage(file)">
          <el-image :src="file.url || ''" fit="cover" />
        </div>
        <div v-else>
          <video preload="auto" :src="file.url" controls="controls">
            您的浏览器不支持 video 标签。
          </video>
        </div>
      </div>
    </div>
  </sc-dialog>
</template>

<script setup>
import { computed, defineProps, defineEmits } from 'vue';
const props = defineProps({
  fileList: {
    type: Array,
    default: () => []
  },
  modelValue: {
    type: Boolean,
    default: false,
  }
})
const emits = defineEmits(['update:modelValue'])
const visible = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emits('update:modelValue', val)
  }
})

const isImage = file => /jpe?g|png|gif/.test(file.type)
</script>

<style lang="scss" scoped>
.file-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .file-item {
    width: 24%;
    padding-bottom: 15%;
    margin-bottom: 10px;
    position: relative;
    >div {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      .el-image, video {
        width: 100%;
        height: 100%;
      }
    }
    &:nth-child(3n) { // 去除第3n个的margin-right
      margin-right: 0;
    }
  }
}
</style>